function ModuleImageManage(doc, container, width, height, user, date, options, message) {
  this._doc = doc;
  this._container = container;
  this._width = width;
  this._height = height;
  this._user = user;
  this._date = date;
  this._options = options;
  this._message = message;
  
  this._images = (this._message['images']) ? this._message['images'] : [];
  this._p = (this._message['idx']) ? this._message['idx'] : 0;
  
  this._object = this._images[this._p];
  this._gui = new ImageManage(this._doc, this._container, this._width, this._height, this._user, this._date, this._options, this._object)._gui;

  this._createElements();
};

ModuleImageManage.prototype._createElements = function() {
  var _self = this;
  
  this._maxNumber = 100;
  this._index = 1;
  this._urls = ['_test/images/0.jpg', '_test/images/1.jpg', '_test/images/2.jpg', '_test/images/3.jpg', '_test/images/4.jpg',
                '_test/images/5.jpg', '_test/images/6.jpg', '_test/images/7.jpg', '_test/images/8.jpg', '_test/images/9.jpg'
               ];
  this._nums = [];

  this._bwidth = this._object.width;
  this._bheight = this._object.height;
  this._notes = (this._object.notes) ? this._object.notes : [];
  this._numbers = (this._object.numbers) ? this._object.numbers : [];
  this._line = (this._object.lines.length == 1) ? this._object.lines[0] : null;
  
  this._backg = document.createElement('div');
  this._backg.style.width = this._bwidth + 'px';
  this._backg.style.height = this._bheight + 'px';
  this._backg.style.position = 'absolute';
  this._backg.style.left = '0px';
  this._backg.style.top = '0px';
  this._gui.imageDiv.appendChild(this._backg);

  this._imageShow();
};

ModuleImageManage.prototype._imageShow = function() {
  var _self = this;
  
  var total = this._images.length;

  this._gui.next.onclick = function() { DOMUtils.removeChildElements(_self._backg);
                                        if (_self._p < total - 1) {
                                          ++_self._p;
                                          _self._gui.image.src = _self._images[_self._p].link;
                                          _self._object = _self._images[_self._p];
                                        } else {
                                          _self._p = 0;
                                          _self._gui.image.src = _self._images[0].link;
                                          _self._object = _self._images[0];
                                        }
                                        _self._createElements.call(_self);
                                      };
  this._gui.prev.onclick = function() { DOMUtils.removeChildElements(_self._backg);
                                        if (_self._p > 0) {
                                          --_self._p;
                                          _self._gui.image.src = _self._images[_self._p].link;
                                          _self._object = _self._images[_self._p];
                                        } else {
                                          _self._p = total-1;
                                          _self._gui.image.src = _self._images[_self._p].link;
                                          _self._object = _self._images[_self._p];
                                        }
                                        _self._createElements.call(_self);
                                      };
  
//  var obj = $('#slider');
//  var s = $("li", obj).length;
//  var w = $("li", obj).width();
//  var h = $("li", obj).height();
//  var sd = 800;
//  obj.width(w); 
//  obj.height(h);
//  obj.css("overflow", "hidden");
//  var ts = s - 1;
//  var t = 0;
//  $("ul", obj).css('width', s * w);
//  $("li", obj).css('float', 'left');
//  
//  $("#next").click(function(){ 
//    animate("next", true);
//    this._index = 1;
//    _self._addLine(this._index);
//  });
//  
//  $("#prev").hide();
//  $("#prev").click(function(){
//    animate("prev", true);
//    this._index = 1;
//    _self._addLine(this._index);
//  });
//  
//  function animate(dir, clicked){
//    var ot = t;
//    switch(dir){
//      case "next":
//        t = (ot >= ts) ?  ts : t+1;
//        break;
//      case "prev":
//        t = (t<=0) ?  0 : t-1;
//        break; 
//      default:
//        break;
//    }
//    
//    var diff = Math.abs(ot - t);
//    var speed = diff * sd;
//    p = (t*w*-1);
//    $("ul", obj).animate({ marginLeft: p }, speed );
// 
//    if(t == ts){
//      $("#next").hide();
//    } else {
//      $("#next").show();
//    }
//    
//    if(t == 0){
//      $("#prev").hide();
//    } else {
//      $("#prev").show();
//    }
//    DOMUtils.removeChildElements(_self._gui.imageLoading);
//    DOMUtils.removeChildElements(_self._backg);
//  };
  
  for (var i = 0, il = this._notes.length; i < il; i++) {
    var note = this._notes[i];
    var div = document.createElement('div');
    div.style.zIndex = '1';
    _self._backg.appendChild(div);
    var p = new ModuleImageNote();
    p._open(div, {idx: this._p, obj: note, exist: true });
  }
  
  this._showNumber();
  for (var j = 0, jl = this._numbers.length; j < jl; j++) {
    var num = this._numbers[j];
    var div = document.createElement('div');
    div.style.zIndex = '1';
    _self._backg.appendChild(div);
    var p = new ModuleImageNumber();
    var urls = this._getImageUrl(num.number);
    p._open(div, {idx: this._p, numbers: this._numbers, back: _self._backg, obj: num, exist: true, urls: urls });
  }
  
  if (this._line) {
    var div = document.createElement('div');
    div.style.zIndex = '1';
    _self._backg.appendChild(div);
    var p = new ModuleImageLine();
    p._open(div, {idx: this._p, obj: this._line, exist: true });
    this._index++;
  }
  
  this._addNote();
  this._addNumber();
  this._addLine();
};

ModuleImageManage.prototype._showNumber = function() {
  var _self = this;
  for (var j = 0, jl = this._numbers.length; j < jl; j++) {
    var num = this._numbers[j];
    var ext = false;
    for (var k = 0,kl = this._nums.length; k < kl; k++) {
      if (this._nums[k] == num.number) {
        ext = true;
      }
    }
    if (!ext) {
      this._nums.push(parseInt(num.number, 10));
    }
  }
};

ModuleImageManage.prototype._addNote = function() {
  var _self = this;
  this._gui.addNote.onclick = function() { var div = document.createElement('div');
                                           div.style.zIndex = '10';
                                           _self._backg.appendChild(div);
                                           var obj = new Object();
                                           obj.track_id = MiscUtils.unique();
                                           obj.image_id = _self._object.id;
                                           obj.width = 30;
                                           obj.height = 30;
                                           obj.top = 30;
                                           obj.left = 30;
                                           obj.text = '';
                                           var p = new ModuleImageNote();
                                           p._open(div, {idx: _self._p, obj: obj});
                                         };
};

ModuleImageManage.prototype._addNumber = function() {
  var _self = this;
  this._gui.addNumber.onclick = function() { var div = document.createElement('div');
                                             div.style.zIndex = '10';
                                             _self._backg.appendChild(div);
                                             var obj = new Object();
                                             obj.track_id = MiscUtils.unique();
                                             obj.image_id = _self._object.id;
                                             obj.width = 30;
                                             obj.height = 30;
                                             obj.top = 10;
                                             obj.left = 10;
                                             obj.number = parseInt(_self._getMinNumber(_self._nums), 10);
                                             _self._numbers.push(obj);
                                             _self._showNumber();
                                             var p = new ModuleImageNumber();
                                             p._open(div, {idx: _self._p, numbers: _self._numbers, back: _self._backg, obj: obj, nums: _self._nums, callback: function(nums) {_self._getMinNumber(nums);} });
                                           };
};

ModuleImageManage.prototype._addLine = function() {
  var _self = this;
  this._gui.addLine.onclick = function() { if (_self._index == 1) {
                                             var obj = new Object();
                                             obj.track_id = MiscUtils.unique();
                                             obj.image_id = _self._object.id;
                                             obj.width = 10;
                                             obj.height = _self._bheight - 1;
                                             obj.top = 0;
                                             obj.left = _self._bwidth / 3;
//                                             new RequestUtils()._write(JSON.stringify([{ n: 'pz_tnfc_ivq_line', a: [obj], r: [] }]), function(result, params) { location.href = '?t=test&i=' + _self._p }, { pos: DOMUtils.findPos(this) });
                                             new RequestUtils()._custom('ezobj', JSON.stringify({ obj: obj, tbl: 'pz_tnfc_ivq_line' }), function(result, params) { location.href = '?t=test&i=' + _self._p }, { php: 'custom.php',  pos: DOMUtils.findPos(this) });
                                           }
                                         };
//  this._gui.addLine._index = index;
//  this._gui.addLine.onclick = function() { var div = document.createElement('div');
//                                           div.style.zIndex = '5';
//                                           _self._backg.appendChild(div);
//                                           if (this._index == 1) {
//                                             var obj = new Object();
//                                             obj.track_id = MiscUtils.unique();
//                                             obj.image_id = _self._object.id;
//                                             obj.width = 10;
//                                             obj.height = _self._bheight - 1;
//                                             obj.top = 0;
//                                             obj.left = _self._bwidth / 3;
//                                             var p = new ModuleImageLine();
//                                             p._open(div, {obj: obj, callbackFunc: function(index) { _self._addLine(index); } });
//                                             this._index--;
//                                           }
//                                         };
};

ModuleImageManage.prototype._getMinNumber = function(nums) {
  for (var i = 1, il = this._maxNumber; i <= il; i++) {
    var exist = false;
    for (var j = 0, jl = nums.length; j < jl; j++) {
      var n = nums[j];
      if (i == n) {
        exist = true;
      }
    }
    if (!exist) {
      return i;
    }
  }
};

ModuleImageManage.prototype._getImageUrl = function(num) {
  var array = num.split("");
  urls = [];
  for (var i = 0, il = array.length; i < il; i++) {
    var n = array[i];
    urls.push(this._urls[n]);
  }
  return urls;
};